home *** CD-ROM | disk | FTP | other *** search
- unit DataFld2;
-
- interface
-
- procedure Register;
-
- implementation
-
- uses
- DsgnIntf, TypInfo, Classes, DB;
-
- type
- TDataField2Property = class(TStringProperty)
- public
- function GetAttributes: TPropertyAttributes; override;
- procedure GetValueList(List: TStrings);
- procedure GetValues(Proc: TGetStrProc); override;
- end;
-
- function TDataField2Property.GetAttributes: TPropertyAttributes;
- begin
- Result := [paValueList, paSortList, paMultiSelect];
- end;
-
- procedure TDataField2Property.GetValueList(List: TStrings);
- var
- Instance: TPersistent;
- PropInfo: PPropInfo;
- DataSource: TDataSource;
- begin
- Instance := GetComponent(0);
- PropInfo := TypInfo.GetPropInfo(Instance.ClassInfo, 'DataSource');
- if (PropInfo <> nil) and (PropInfo^.PropType^.Kind = tkClass) then
- begin
- DataSource := TObject(GetOrdProp(Instance, PropInfo)) as TDataSource;
- if (DataSource <> nil) and (DataSource.DataSet <> nil) then
- DataSource.DataSet.GetFieldNames(List);
- end;
- end;
-
- procedure TDataField2Property.GetValues(Proc: TGetStrProc);
- var
- I: Integer;
- Values: TStrings;
- begin
- Values := TStringList.Create;
- try
- GetValueList(Values);
- for I := 0 to Values.Count - 1 do
- Proc(Values[I]);
- finally
- Values.Free;
- end;
- end;
-
- procedure Register;
- begin
- RegisterPropertyEditor(TypeInfo(String), TComponent,
- 'DataField2', TDataField2Property)
- end;
-
- end.
-